﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FileManager.Model;
using System.IO;
using System.Text;
using System.Windows.Threading;


namespace FileManager.ViewModel
{
    internal partial class MainWindowViewModel : ObservableObject
    {
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(ProgressDisplay))]
        [NotifyCanExecuteChangedFor(nameof(NextFileCommand))]
        [NotifyCanExecuteChangedFor(nameof(PreFileCommand))]
        private int _idx;

        [NotifyPropertyChangedFor(nameof(ProgressDisplay))]
        [ObservableProperty]
        [NotifyCanExecuteChangedFor(nameof(NextFileCommand))]
        [NotifyCanExecuteChangedFor(nameof(PreFileCommand))]
        private int _maxNum;
        private MainWindow view;
        public FileMetadataCollection Meta2Show = new FileMetadataCollection();
        public FileMetadataCollection oriFiles = new FileMetadataCollection();
        
        [ObservableProperty]
        private string _movePath;
        [ObservableProperty]
        private bool _moveOther;

        [ObservableProperty]
        private bool _showAll;
        [ObservableProperty]
        private string _statusBarMessage;

        [ObservableProperty]
        private bool _openDir;

        [ObservableProperty]
        private string _fileDetal;
        [ObservableProperty]
        private bool _isStatusBarMessageVisible;
        private DispatcherTimer _statusBarTimer;
        [ObservableProperty]
        private string _dataPath;

        [ObservableProperty]
        private MetaData _currentFile;

        public string ProgressDisplay => $"{Idx}/{MaxNum}";
        public MainWindowViewModel(MainWindow view)
        {
            _idx = 0;
            this.view = view;
            var Ini=new MysToolCore.InIReader("config",Encoding.UTF8);
            _statusBarTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(2)
            };
            _statusBarTimer.Tick += OnStatusBarTimerTick;
            _movePath = Ini.ReadString("Base", "savePath", "E:\\文件整理\\tmp");
        }


        partial void OnIdxChanged(int value)
        {
            view.Update();
        }


    }
}
